﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using 文件传PDA工具;
using System.Windows.Forms;
namespace YZZ
{
    class InformationModel
    {
        internal static void 加载配置(Form1 me)
        {
            if (me._table == null)
                return;
            if (me._table.Rows.Count == 0)
                return;

            DataRow 参数 = me.参数;
            foreach (DataRow row in me._table.Rows)
            {
                switch (row["项目名称"].ToString())
                {
                    case "服务器":
                        参数["服务器"] = row["项目内容"].ToString();
                        break;
                    case "端口":
                        参数["端口"] = row["项目内容"].ToString();
                        break;
                    case "账号":
                        参数["账号"] = row["项目内容"].ToString();
                        break;
                    case "密码":
                        参数["密码"] = row["项目内容"].ToString();
                        break;
                    case "文件夹":
                        参数["文件夹"] = row["项目内容"].ToString();
                        break;
                    case "清理数据备份":
                        参数["清理数据备份"] = row["项目内容"].ToString();
                        break;
                    case "上传wince":
                        参数["上传wince"] = row["项目内容"].ToString();
                        break;
                    case "上传xmlce":
                        参数["上传xmlce"] = row["项目内容"].ToString();
                        break;
                    case "上传print":
                        参数["上传print"] = row["项目内容"].ToString();
                        break;
                    case "上传info":
                        参数["上传info"] = row["项目内容"].ToString();
                        break;
                    case "测试版文件夹":
                        参数["测试版文件夹"] = row["项目内容"].ToString();
                        break;
                    case "正式版文件夹":
                        参数["正式版文件夹"] = row["项目内容"].ToString();
                        break;
                    case "传PDA":
                        参数["传PDA"] = row["项目内容"].ToString();
                        break;
                    case "发布测试版":
                        参数["发布测试版"] = row["项目内容"].ToString();
                        break;
                    case "发布正式版":
                        参数["发布正式版"] = row["项目内容"].ToString();
                        break;
                    case "测试版转正式":
                        参数["测试版转正式"] = row["项目内容"].ToString();
                        break;
                }
            }
            foreach (object _ctrl in me.Controls)
            {
                switch (((Control)_ctrl).Name)
                {
                    case "groupPDA":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Text_Server":
                                    ((TextBox)gCtrl).Text = 参数["服务器"].ToString().Trim();
                                    break;
                                case "Text_Port":
                                    ((TextBox)gCtrl).Text = 参数["端口"].ToString().Trim();
                                    break;
                                case "Text_User":
                                    ((TextBox)gCtrl).Text = 参数["账号"].ToString().Trim();
                                    break;
                                case "Text_Pass":
                                    ((TextBox)gCtrl).Text = 参数["密码"].ToString().Trim();
                                    break;
                                case "Text_TargetFolder":
                                    ((TextBox)gCtrl).Text = 参数["文件夹"].ToString().Trim();
                                    break;
                            }
                        }
                        break;
                    case "groupOptions":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Check_ClearBackup":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["清理数据备份"].ToString());
                                    break;
                                case "Check_Wince":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["上传wince"].ToString());
                                    break;
                                case "Check_Xmlce":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["上传xmlce"].ToString());
                                    break;
                                case "Check_Print":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["上传print"].ToString());
                                    break;
                                case "Check_Info":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["上传info"].ToString());
                                    break;
                                case "Check_PDA":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["传PDA"].ToString());
                                    break;
                                case "Check_Develop":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["发布测试版"].ToString());
                                    break;
                                case "Check_Release":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["发布正式版"].ToString());
                                    break;
                                case "Check_Develop2Release":
                                    ((CheckBox)gCtrl).Checked = YZZ.Tools.StringToBool(参数["测试版转正式"].ToString());
                                    break;
                            }
                        }
                        break;
                    case "groupDevelop":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Text_Develop":
                                    ((TextBox)gCtrl).Text = 参数["测试版文件夹"].ToString();
                                    break;
                            }
                        }
                        break;
                    case "groupRelease":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Text_Release":
                                    ((TextBox)gCtrl).Text = 参数["正式版文件夹"].ToString();
                                    break;
                            }
                        }
                        break;
                }
            }
            me.参数 = 参数;
        }

        internal static void 写入配置(Form1 me)
        {
            me.ResetTable();


            DataRow 参数 = me.参数;
            foreach (object _ctrl in me.Controls)
            {
                switch (((Control)_ctrl).Name)
                {
                    
                    case "groupPDA":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Text_Server":
                                    参数["服务器"] = ((TextBox)gCtrl).Text;
                                    break;
                                case "Text_Port":
                                    参数["端口"] = ((TextBox)gCtrl).Text;
                                    break;
                                case "Text_User":
                                    参数["账号"] = ((TextBox)gCtrl).Text;
                                    break;
                                case "Text_Pass":
                                    参数["密码"] = ((TextBox)gCtrl).Text;
                                    break;
                                case "Text_TargetFolder":
                                    参数["文件夹"] = ((TextBox)gCtrl).Text;
                                    break;
                            }
                        }
                        break;
                    case "groupOptions":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Check_ClearBackup":
                                    参数["清理数据备份"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Wince":
                                    参数["上传wince"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Xmlce":
                                    参数["上传xmlce"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Print":
                                    参数["上传print"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Info":
                                    参数["上传info"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_PDA":
                                    参数["传PDA"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Develop":
                                    参数["发布测试版"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Release":
                                    参数["发布正式版"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                                case "Check_Develop2Release":
                                    参数["测试版转正式"] = ((CheckBox)gCtrl).Checked.ToString();
                                    break;
                            }
                        }
                        break;
                    case "groupDevelop":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Text_Develop":
                                    参数["测试版文件夹"] = ((TextBox)gCtrl).Text;
                                    break;
                            }
                        }
                        break;
                    case "groupRelease":
                        foreach (object gCtrl in ((GroupBox)_ctrl).Controls)
                        {
                            switch (((Control)gCtrl).Name)
                            {
                                case "Text_Release":
                                    参数["正式版文件夹"] = ((TextBox)gCtrl).Text;
                                    break;
                            }
                        }
                        break;
                }
            }
            foreach (DataColumn col in 参数.Table.Columns)
            {
                DataRow row = me._table.NewRow();
                row["项目名称"] = col.ColumnName;
                row["项目内容"] = 参数[col.ColumnName];
                me._table.Rows.Add(row);
            }
            me.参数 = 参数;

        }
    }
}
